package com.vincent.template.commons.base;

import com.vincent.template.commons.exception.Vct520Exception;

import java.util.HashMap;

/**
 * @author Vincent Wang
 * @date 2021/3/25 12:47
 */
public class VctVo<T> extends HashMap<String, T> {

    public static VctVo<Object> of(Object... args) {
        int size = args.length;
        Vct520Exception.throwIfTrue(size == 0 || size % 2 != 0,
                "The number of args must be an even number greater than 0");
        int times = size / 2;
        VctVo<Object> vctVo = new VctVo<>();
        for (int i = 0; i < times; i++) {
            int offset = i * 2;
            vctVo.put(args[offset].toString(), args[offset + 1]);
        }
        return vctVo;
    }

    public static <T> VctVo<T> single(String key, T value) {
        VctVo<T> single = new VctVo<>();
        single.put(key, value);
        return single;
    }

    public static <T> VctVo<T> id(T value) {
        return single("id", value);
    }

}
